<template>
	<view class="container">
		<view class="noticeitem" v-for="(item,index) in list" :key="index" @click="goDetail(item.id)">
			<view class="flex  ">
				<image :src="$util.img('image/huaImg/12.png')" class="noicon m-r-10" mode=""></image>
				<text>{{item.title}}</text>
			</view>
			<view class="n-content font-24">{{item.content}}</view>
			<view class="n-time flex-between">
				{{$util.timeStampTurnTime(item.create_time)}}
				<view class="flex-y-center font-24 c-78" v-if="type == 'group'">
					查看详情
					<u-icon name="arrow-right" color="#788096" size="14"></u-icon>
				</view>
			</view>
		</view>
		<emptyData :width="empty.width" :height="empty.height" :text="empty.text" :icon="empty.icon" :marginTop="empty.marginTop" v-if="list.length == 0"></emptyData>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//分页数据
				list:[],
				page: 1,
				empty: {
					width: 135,
					height: 134,
					text: '暂无数据',
					icon: '/image/emptyAddress.png',
					marginTop: 100
				},
				type: 'mall'
			};
		},
		onLoad(data) {
			this.type = data.type || 'mall'
			this.getList()
			// 增加方法-设置消息全部已读
			this.setReadAllNotice()
		
		},
		onShow() {
			
		},
		onReachBottom() {
		  this.page++
		  this.getList()
		},
		methods:{
			setReadAllNotice() {
				this.$api.sendRequest({
			      url: "/sitemessage/api/sitemessage/editAllSeed",
			      data: {
			        sub_type: this.type,
			      },
			      success: res => {
			        if(res.code == 0) {
			          console.log('全部已读')
			        } 
			      }
			    })
			},
			goDetail(id) {
				if(this.type == 'group') this.$util.redirectTo('/otherpages/butler/noticeDetail?id=' + id)
				
			},
			getList() {
			  
			  this.$api.sendRequest({
			      url: "/sitemessage/api/sitemessage/getSiteMemberSubMessageGroupList",
			      data: {
			        page: this.page,
					page_size: 20,
			        sub_type: this.type,
			      },
			      success: res => {
			        if(res.code == 0) {
			         if(this.page == 1) this.list = []
			         this.list = [...this.list, ...res.data.list]
			         
			        } 
			      }
			    })
			},
		}
	}
</script>

<style lang="scss" scoped>
	.noticeitem{
		margin: 24rpx;
		padding: 24rpx;
		border-radius: 24rpx;
		background-color: #fff;
		.noicon{
			width: 46rpx;
			height: 46rpx;
		}
		.n-content{
			color: #788096;
			padding: 10rpx 0;
			margin-bottom: 10rpx;
			border-bottom: 1px solid #E7E8EB;
		}
		.n-time{
			font-size: 24rpx;
			color: #B8BAC2;
		}
	}
</style>
